export default {

    //通过组合方法计算注数
    //从allNum个球中选出selectnum,共多少注
    //返回数字类型


    info: function (name, obj) {
        console.info("begin==" + name)
        console.info(obj)
        console.info("end===" + name)
    },
    warn: function (name, obj) {
        console.warn("begin==" + name)
        console.warn(obj)
        console.warn("end===" + name)
    },

    computeZs: function (selectNum, allNum) {

        let denominator = 1;
        let numerator = 1;
        let nCompNum = 1;

        if (selectNum < allNum) {
            return 0;
        }
        if (0 == allNum) {
            return 1;
        }
        if (selectNum == allNum) {
            return 1;
        }
        if (allNum > selectNum / 2 + 1) {
            allNum = selectNum - allNum;
        }
        //计算单个组合的个数
        for (let j = 1; j <= allNum; j++) {
            numerator *= (selectNum - (j - 1));
            denominator *= j;
        }
        nCompNum = numerator / denominator;
        console.log("num" + nCompNum);
        return nCompNum;
    },

    //返回从begin==end之间的随机数
    randNum: function (begin, end) {
        return Math.floor(Math.random() * end + begin);

    },


    formatDate: function (theDate, fmt) { //author: meizz 
        var o = {
            "M+": theDate.getMonth() + 1, //月份 
            "d+": theDate.getDate(), //日 
            "h+": theDate.getHours(), //小时 
            "m+": theDate.getMinutes(), //分 
            "s+": theDate.getSeconds(), //秒 
            "q+": Math.floor((theDate.getMonth() + 3) / 3), //季度 
            "S": theDate.getMilliseconds() //毫秒 
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (theDate.getFullYear() + "")
            .substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;

    },

    //通过组合方法计算注数
    //从begin到end之间产生total个数量
    //返回数字类型

    randBall: function (begin, end, count) {

        let randBall = new Set();

        //随机数可能会重复，认为高于10倍肯定能产生不同的数据
        //可以用死循环，但是为了避免意外，选择10倍的数量
        for (let i = 0; i < count * 10; i++) {
            let num = this.randNum(begin, end);
            let ball = ""
            if (num < 10) {
                ball = "0" + num.toString()
            } else {
                ball = num.toString()
            }

            randBall.add(ball);
            if (randBall.size == count) {

                return Array.from(randBall).sort();
            }

        }
        return [];


    }

};









